-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread-safe access to PublisherData #278
Conversation
9d3274d
to
0053d8d
Compare
47a876c
to
5b6ee63
Compare
1af387e
to
9c100ac
Compare
Signed-off-by: Yadunund <[email protected]>
5b6ee63
to
145a849
Compare
Signed-off-by: Yadunund <[email protected]>
Signed-off-by: Yadunund <[email protected]>
Signed-off-by: Yadunund <[email protected]>
378262a
to
6f0186d
Compare
Signed-off-by: Yadunund <[email protected]>
6f0186d
to
f99e377
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some mirmo things, but overall LGTM
std::lock_guard<std::mutex> lock(mutex_); | ||
return gid_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is returning a raw pointer, this is probably not thread-safe.
That said, from what I can tell there is only one caller of this API, from rmw_get_gid_for_publisher
. And there, what we are doing is copying the data into an out parameter.
That suggests to me that this function should be something like:
const void PublisherData::copy_gid(rmw_gid_t * gid) const
{
std::lock_guard<std::mutex> lock(mutex_);
memcpy(gid->data, gid_, RMW_GID_STORAGE_SIZE);
}
(and then update the caller down below as needed). That way we are doing the copy under the lock, which should be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Also had to do something similar for copying the GID into the attachment map 4edbee2
Signed-off-by: Yadunund <[email protected]>
Signed-off-by: Yadunund <[email protected]>
This PR replaces
class rmw_publisher_data_t
withclass PublisherData
which provides thread-safe access to publisher functions. An instance ofPublisherData
is created via theNodeData
class.rmw_publisher->data
is now set tormw_node_t
. The assumption here is that the node outlives the publisher similar to the assumption that the context outlives the node. From thisrmw_node_t
raw_ptr, we are able to obtain it'sNodeData
and then lookup thePublisherData
for the publisher.One nice thing this PR introduces is the mechanism where shutting down or destroying a parent entity, will shutdown the child entities. Eg. If
rclcpp::shutdown()
is invoked, it will firstshutdown
all thePublisherData
, thenNodeData
, and finally the context. We also check for shutdown in the destructor. This is helpful when someone callsnode.reset
there by destroying anrclcpp::Node
; this will now shutdown all child entities (onlyPublisherData
so far) and then shutdown the node before clearing memory. We also check foris_shutdown
before creating a publisher, publishing a message, etc. These principles will be extended to other entities in subsequent PRs.